package cm.example.shoppingplatformspringboot.controller;

import cm.example.shoppingplatformspringboot.entity.ShopCarDTO;
import cm.example.shoppingplatformspringboot.service.CartService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/car")
public class CartController {
    @Resource
    private CartService cartService;

    //查看购物车
    @GetMapping("/selectCartByUserId")
    public List<ShopCarDTO> selectCartByUserId(@RequestParam int userId) {
        return cartService.selectCartByUserId(userId);
    }

    //加入购物车
    @PostMapping("/insertShopCart")
    public int insertShopCart(@RequestBody ShopCarDTO shopCarDTO) {
        return cartService.insertShopCart(shopCarDTO);
    }

    // 修改购物车商品项数量
    @PutMapping("/updateCartItemNum")
    public int updateCartItemNum(@RequestParam int id, @RequestParam int num) {
        return cartService.updateCartItemNum(id, num);
    }

    // 删除购物车商品项
    @DeleteMapping("/deleteCartItem")
    public int deleteCartItem(@RequestParam int userId, @RequestParam int goodItemId) {
        return cartService.deleteCartItem(userId, goodItemId);
    }

    // 清空购物车
    @DeleteMapping("/clearCart")
    public int clearCart(@RequestParam int userId) {
        return cartService.clearCart(userId);
    }
}
